import { reqGetHomeData } from '@/api/home'
Page({
  /**
   * 页面的初始数据
   */
  data: {
    bannerList: [],
    categoryList: [],
    recommendList: [],
    likeList: [],
    hotList: [],
    // 骨架屏
    loading: true
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getHomePageData()
  },

  // 并发获取首页数据
  async getHomePageData() {
    const res = await reqGetHomeData()
    this.setData({
      bannerList: res[0].data,
      categoryList: res[1].data,
      recommendList: res[2].data,
      likeList: res[3].data,
      hotList: res[4].data,
      loading: false
    })
  },
  goProductList(e) {
    const category1Id = e.currentTarget.dataset.id
    wx.navigateTo({
      url: `/modules/goodsModule/pages/goods-list/goods-list?category1Id=${category1Id}`
    })
  },
  handleGoRecommendList(e) {
    const category2Id = e.currentTarget.dataset.id
    wx.navigateTo({
      url: `/modules/goodsModule/pages/goods-list/goods-list?category2Id=${category2Id}`
    })
  },

  onShareAppMessage: function () {
    return {
      title: '送给心爱的她',
      path: '/pages/index/index',
      imageUrl: '../../assets/images/love.jpg'
    }
  },
  onShareTimeline: function () {}
})
